#!/usr/bin/python3
#******************************************************************************
# Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
# licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#     http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# ******************************************************************************/
"""
This is source counter class
"""

import re
import time
import gitee

class IssueCounter(object):
    """
    source counter
    """
    def __init__(self):
        self.gitee = gitee.Gitee()

    def get_merged_branches(self, issue_id, repo, owner):
        """
        Get merged branches of issue
        """
        merged_branches = []
        raw_list = self.gitee.get_issue_merged_branches(issue_id, repo, owner)
        for info in raw_list:
            head_dict = info.get("base")
            if not head_dict:
                continue
            branch = head_dict.get("label")
            if not branch or branch in merged_branches:
                continue
            merged_branches.append(branch)
        return merged_branches

    